#ifndef AVALON_BUFFERREADER_HPP
#define AVALON_BUFFERREADER_HPP
#include <string>
#include "Avalon/IO/Buffer.hpp"
#include "Avalon/IO/Reader.hpp"

namespace Avalon {
namespace IO {

  /*! \class BufferReader
   *  \brief Reads data from a Buffer.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class BufferReader : public Reader {
    public:

      //! Constructs a BufferReader from a Buffer.
      /*!
        \param source The Buffer to read from.
      */
      BufferReader(const Buffer& source);

      //! Constructs a BufferReader from a string.
      /*!
        \param source The string to read from.
      */
      BufferReader(const std::string& source);

      virtual ~BufferReader();

      virtual bool IsAtEndOfDataSource();

      virtual Threading::Async<int>::Ptr Read(Buffer* destination);

      virtual Threading::Async<int>::Ptr Read(void* destination, int size);

      virtual Threading::Async<int>::Ptr Read(Buffer* destination, int size);

    private:
      Buffer m_source;
      const char* m_readIterator;
      int m_readRemaining;
  };
}
}

#endif // AVALON_BUFFERREADER_HPP
